package com.fulu.game.bi.controller.room;

import com.fulu.game.bi.entity.dto.VoiceOverviewListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.room.RoomStatAllUserDayRealTimeVO;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.service.impl.room.VoiceOverviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 语言互动-总览
 */
@RestController
@RequestMapping("/api/voice/overview")
@Slf4j
public class VoiceOverviewController {

    @Autowired
    private VoiceOverviewService voiceOverviewService;

    /**
     * 语言互动总览-实时数据
     */
    @RequestMapping("/real-time")
    public Result<List<RoomStatAllUserDayRealTimeVO>> realTime() {
        return Result.success().data(voiceOverviewService.overviewRealTime());
    }

    /**
     * 语言互动总览-列表
     */
    @RequestMapping("/list")
    public Result list(VoiceOverviewListDTO voiceOverviewListDTO) {
        return Result.success().data(voiceOverviewService.list(voiceOverviewListDTO));
    }

    /**
     * 语言互动总览-列表-导出
     * @param voiceOverviewListDTO
     */
    @PostMapping("/export")
    public void export(VoiceOverviewListDTO voiceOverviewListDTO) {
        voiceOverviewService.export(voiceOverviewListDTO);
    }


    /**
     * 语言互动总览-折线图
     *
     * @return
     */
    @RequestMapping("/line-chart")
    public Result<List<NameMsgVO>> stat() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("钻石消费", "virtualMoneyAll");
        cacheMap.put("消费人数", "consumeUserNum");
        cacheMap.put("消费次数", "consumeNum");
        cacheMap.put("进厅人数", "enterRoomUserNum");
        cacheMap.put("进厅次数", "enterRoomNum");
        cacheMap.put("新增收藏", "addCollectNum");
        cacheMap.put("用户平均停留时长", "userStayTimeAvg");
        cacheMap.put("停留>5分钟用户数", "stayFiveMinUserNum");

        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());

        return Result.success().data(list).msg("获取成功");
    }

}
